home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 24
/
Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso
/
Aminet
/
dev
/
c
/
AmiVoGL_MDEV.lha
/
drivers
/
sun.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-04-12
|
16KB
|
906 lines
/*
* Vogl/Vogle driver for Sun using sunview.
*
*/
/*
* define VOGLE for VOGLE library or leave blank for VOGL library
#define VOGLE 1
*/
#undef VOGLE
#include <stdio.h>
#include <suntool/sunview.h>
#include <suntool/canvas.h>
#include <fcntl.h>
#include <errno.h>
#ifdef SUN_3_5
#define event_action event_id
#endif
#ifdef VOGLE
#include "vogle.h"
#else
#include "vogl.h"
#endif
#define CMAPSIZE 256
#define STDFONTDIR "/usr/lib/fonts/fixedwidthfonts/"
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define OP_WHITE (PIX_SRC | PIX_COLOR(7) | PIX_DONTCLIP)
#define OP_BLACK (PIX_SRC | PIX_COLOR(0) | PIX_DONTCLIP)
#define COL_WHITE 7
#define COL_BLACK 0
static Pixwin *pw_tmp, *pw;
#ifdef BASE_COL_SET
static Pixwin *pw0;
#endif
static Pixrect *backb;
static Pixfont *font_id;
static int wfd, blanket_win;
static int oldflags;
static int pwfd, h, w;
static int colour;
static Rect wrect;
static char use_sunview_canvas = 0;
#define DASHED 1
#define FATLINES 2
static unsigned char lineflags = 0;
static Pr_brush brush = {1};
static Pr_texture *t = (Pr_texture *)NULL;
static Pr_texture tex = {
(short *)NULL,
0,
{1, 1, 1, 0},
0,
};
/*
* default colour map
*/
static int colnum = 8;
static u_char red[CMAPSIZE] = {
0, 255, 0, 255, 0, 255, 0, 255, 0,
},
green[CMAPSIZE] = {
0, 0, 255, 255, 0, 0, 255, 255, 0,
},
blue[CMAPSIZE] = {
0, 0, 0, 0, 255, 255, 255, 255, 0,
};
/*
* redisplay
*
* redisplay the window.
*/
static void redisplay(void)
{
pw_damaged(pw);
pw_repairretained(pw);
pw_donedamaged(pw);
}
/*
* To be called from a resize procedure from withing sunview
*/
int vo_sunview_canvas_size(
int sw,
int sh)
{
w = sw;
h = sh;
vdevice.sizeX = vdevice.sizeY = MIN(h, w);
vdevice.sizeSx = w;
vdevice.sizeSy = h;
if (pw->pw_prretained) {
mem_destroy(pw->pw_prretained);
backb = pw->pw_prretained = mem_create(w, h, vdevice.depth);
}
}
/*
* vo_sunview_canvas
*
* Tells VOGLE/VOGL to use a supplied sunview pixwin
*/
int vo_sunview_canvas(
Canvas canvas,
int cw,
int ch)
{
pw = canvas_pixwin(canvas);
use_sunview_canvas = 1;
w = cw;
h = ch;
vdevice.sizeX = vdevice.sizeY = MIN(h, w);
vdevice.sizeSx = w;
vdevice.sizeSy = h;
vdevice.depth = pw->pw_pixrect->pr_depth;
if (!pw->pw_prretained) /* Make us retained */
backb = pw->pw_prretained = mem_create(w, h, vdevice.depth);
/*
* Set up the color map.
*/
if (vdevice.depth > 1) {
pw_setcmsname(pw, "vogle");
pw_putcolormap(pw, 0, colnum, red, green, blue);
}
wfd = (int)window_get(canvas, WIN_FD);
/*
* Set non-blocking input for window.
oldflags = fcntl(wfd, F_GETFL, 0);
if (fcntl(wfd, F_SETFL, FNDELAY) < 0) {
perror("F_SETFL");
exit(1);
}
*/
pw_batch_on(pw);
#ifndef VOGLE
vdevice.devname = "sun";
#endif
return(1);
}
/*
* SUN_init
*
* initialises drawing canvas to occupy current window
*/
int SUN_init(void)
{
int i, prefx, prefy, prefxs, prefys, bw;
char name[WIN_NAMESIZE];
Inputmask imk, imp;
int rootfd;
if (use_sunview_canvas)
return(1);
pw = (Pixwin *)NULL;
#ifdef BASE_COL_SET
pw0 = pw;
#endif
/*
* get the gfx win so we have some default sizes to use
*/
we_getgfxwindow(name);
pwfd = open(name, 2);
win_getrect(pwfd, &wrect);
/*
* Get the input masks of the base window...
*/
win_get_pick_mask(pwfd, &imp);
win_get_kbd_mask(pwfd, &imk);
/*
* get a new window (either going to be a blanket window or
* a window in it's own right)
*/
if ((wfd = win_getnewwindow()) == -1) {
fprintf(stderr, "No new windows!\n");
exit(1);
}
getprefposandsize(&prefx, &prefy, &prefxs, &prefys);
if (prefx > -1) {
wrect.r_left = prefx;
wrect.r_top = prefy;
}
if (prefxs > -1) {
wrect.r_width = prefxs;
wrect.r_height = prefys;
}
w = wrect.r_width;
h = wrect.r_height;
bw = 3;
if (prefx > -1 || prefxs > -1) {
/*
* Make room for a 3 pixel border
*/
if (wrect.r_left <= 2)
wrect.r_left = 0;
else
wrect.r_left -= bw;
if (wrect.r_top <= 2)
wrect.r_top = 0;
else
wrect.r_top -= bw;
wrect.r_width += 2 * bw;
wrect.r_height += 2 * bw;
win_setrect(wfd, &wrect);
/*
* get the parent (probably full screen window)
* so we can size our window to any size we like
* on the screen.
*/
we_getparentwindow(name);
rootfd = open(name, 2);
win_setlink(wfd, WL_PARENT, win_fdtonumber(rootfd));
win_setlink(wfd, WL_COVERED, WIN_NULLLINK);
win_insert(wfd);
wmgr_top(wfd, rootfd);
pw = pw_open(wfd);
#ifdef BASE_COL_SET
/*
* Get the pixrect for the window that we started in
* so we can set it's colourmap as well
*/
pw0 = pw_open(pwfd);
#endif
close(rootfd);
blanket_win = 0;
} else {
win_insertblanket(wfd, pwfd);
pw = pw_region(pw_open(wfd), 0, 0, w, h);
blanket_win = 1;
}
/*
* Set non-blocking input for window.
*/
oldflags = fcntl(wfd, F_GETFL, 0);
if (fcntl(wfd, F_SETFL, FNDELAY) < 0) {
perror("F_SETFL");
exit(1);
}
/*
* Setup the input masks for window.
*/
win_set_kbd_mask(wfd, &imk);
win_set_pick_mask(wfd, &imp);
vdevice.depth = pw->pw_pixrect->pr_depth;
/*
* Set up the color map.
*/
if (vdevice.depth > 1) {
pw_setcmsname(pw, "vogle");
pw_putcolormap(pw, 0, colnum, red, green, blue);
#ifdef BASE_COL_SET
if (pw0 != (Pixwin *)NULL) {
pw_setcmsname(pw0, "vogle");
pw_putcolormap(pw0, 0, colnum, red, green, blue);
}
#endif
}
if (prefx > -1 || prefxs > -1) {
/*
* Draw the border...
*/
int x0, y0, x1, y1;
x0 = y0 = 0;
x1 = wrect.r_width - 1;
y1 = 0;
pw_vector(pw, x0, y0, x1, y1, OP_WHITE, COL_WHITE);
pw_vector(pw, x0 + 2, y0 + 2, x1 - 2, y1 + 2, OP_WHITE, COL_WHITE);
pw_vector(pw, x0 + 1, y0 + 1, x1 - 1, y1 + 1, OP_BLACK, COL_BLACK);
x0 = x1;
y0 = y1;
x1 = x0;
y1 = wrect.r_height - 1;
pw_vector(pw, x0, y0, x1, y1, OP_WHITE, COL_WHITE);
pw_vector(pw, x0 - 2, y0 + 2, x1 - 2, y1 - 2, OP_WHITE, COL_WHITE);
pw_vector(pw, x0 - 1, y0 + 1, x1 - 1, y1 - 1, OP_BLACK, COL_BLACK);
x0 = x1;
y0 = y1;
x1 = 0;
y1 = wrect.r_height - 1;
pw_vector(pw, x0, y0, x1, y1, OP_WHITE, COL_WHITE);
pw_vector(pw, x0 - 2, y0 - 2, x1 + 2, y1 - 2, OP_WHITE, COL_WHITE);
pw_vector(pw, x0 - 1, y0 - 1, x1 + 1, y1 - 1, OP_BLACK, COL_BLACK);
x0 = x1;
y0 = y1;
x1 = 0;
y1 = 0;
pw_vector(pw, x0, y0, x1, y1, OP_WHITE, COL_WHITE);
pw_vector(pw, x0 + 2, y0 - 2, x1 + 2, y1 + 2, OP_WHITE, COL_WHITE);
pw_vector(pw, x0 + 1, y0 - 1, x1 + 1, y1 + 1, OP_BLACK, COL_BLACK);
pw_tmp = pw;
pw = pw_region(pw_tmp, 3, 3, w, h);
pw_close(pw_tmp);
}
backb = pw->pw_prretained = mem_create(w, h, vdevice.depth);
signal(SIGWINCH, redisplay);
/*
* Let VOGLE/VOGL know about the window size.
*/
vdevice.sizeX = vdevice.sizeY = MIN(w, h);
vdevice.sizeSx = w;
vdevice.sizeSy = h;
/*
* Set up batching.....(for speed and "pseudo" double buffering)
*/
pw_batch_on(pw);
return(1);
}
/*
* SUN_exit
*
* cleans up before returning the window to normal.
*/
int SUN_exit(void)
{
long nbytes;
int i;
Event event;
if (use_sunview_canvas)
return(1);
/*
* Flush all events for this window.
*
* While doing non-blocking input input_readevent returns -1 and
* errno == EWOULDBLOCK when everything has been read, so if
* errno != EWOULDBLOCK then something naughty happened...
*/
while (input_readevent(wfd, &event) >= 0)
;
if (errno != EWOULDBLOCK) {
perror("SUN_exit(flushing), input_readevent");
exit();
}
/*
* reset wfd to blocking input.
*/
if (fcntl(wfd, F_SETFL, oldflags) < 0) {
perror("oldflags, F_SETFL");
exit(1);
}
if (blanket_win)
win_removeblanket(wfd);
else
win_remove(wfd);
signal(SIGWINCH, SIG_DFL);
return(1);
}
/*
* SUN_draw
*
* draws a line from the current graphics position to (x, y).
*
* Note: (0, 0) is defined as the top left of the window on a sun (easy
* to forget).
*/
int SUN_draw(
int x,
int y)
{
if (!lineflags) /* If thin and solid */
pw_vector(pw, vdevice.cpVx, vdevice.sizeSy - vdevice.cpVy, x, vdevice.sizeSy - y, PIX_SRC | PIX_COLOR(colour), colour);
else /*